/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package rps;

import static rps.RPSEnum.PAPER;
import static rps.RPSEnum.ROCK;
import static rps.RPSEnum.SCISSORS;
import static rps.Result.LOST;
import static rps.Result.TIE;
import static rps.Result.WIN;

/**
 *
 * @author Valentin
 */
public class RockPaperScissors {
    
    public Result play(RPSEnum p1, RPSEnum p2)
    {
        Result resultat=LOST;
        
        if(p1==PAPER && p2==ROCK)
        {
            resultat=WIN;
        }
        
        if(p1==ROCK && p2==SCISSORS)
        {
            resultat=WIN;
        }
        
        if(p1==SCISSORS && p2==PAPER)
        {
            resultat=WIN;
        }
        
        if(p1==p2)
        {
            resultat=TIE;
        }
        
        return resultat;
    }
    
    
    
    public Result play(Player p1, Player2 p2){
        Result resultat=TIE;
        int score1=0;
        int score2=0;
        int nbManche=p1.getNb();
        RPSEnum coup1, coup2;
        
        for(int i=0; i<nbManche; i++){
            coup1 = p1.getNextMove();
            coup2 = p2.getNextMove();
            if(play(coup1, coup2)==WIN){
                score1++;
            }
            else if(play(coup1, coup2)==LOST){
                score2++;
            }
            else if(play(coup1, coup2)==TIE){
                score1++;
                score2++;
            }
            
         if(score1>score2){
             resultat=WIN;
         }
         else if(score1<score2){
             resultat=LOST;
         }
    }
        
        return resultat;
    }
    
}
